package com.smedi.ismedi.inmail.core.application.query.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.QueryListMessageRecordRequest;
import com.smedi.ismedi.inmail.api.dto.request.QueryPageMessageRecordRequest;
import com.smedi.ismedi.inmail.core.application.query.MessageQueryService;
import com.smedi.ismedi.inmail.core.application.query.vo.MessageRecordVo;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.model.MessageRecordEntity;
import com.smedi.ismedi.inmail.core.port.adapter.persistence.mybatis.mapper.MessageRecordMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class MessageQueryServiceImpl implements MessageQueryService {
    private final DozerUtil dozerUtil;

    private final MessageRecordMapper messageRecordMapper;

    @Override
    public List<MessageRecordVo> queryMessageRecordList(QueryListMessageRecordRequest queryListMessageRecordRequest) {
        return dozerUtil.convertor(messageRecordMapper.doList(queryListMessageRecordRequest), MessageRecordVo.class);
    }

    @Override
    public IPage<MessageRecordVo> queryMessageRecordPage(QueryPageMessageRecordRequest queryPageMessageRecordRequest) {
        IPage<MessageRecordVo> iPage = new Page<>(queryPageMessageRecordRequest.getPageNum(), queryPageMessageRecordRequest.getPageSize());
        IPage<MessageRecordEntity> messageRecordEntityIPage = messageRecordMapper.doListPage(iPage, queryPageMessageRecordRequest);
        iPage.setRecords(dozerUtil.convertor(messageRecordEntityIPage.getRecords(), MessageRecordVo.class));
        return iPage;
    }
}
